package com.my.easymall.web;


import com.my.easymall.domain.User;
import com.my.easymall.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @auther Summerday
 *
 * Ajax异步响应用户名查重
 */
@WebServlet("/AjaxCheckUsernameServlet")
public class AjaxCheckUsernameServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //ajax用户名查重
        String username = request.getParameter("username");
        User user = new User();
        user.setUsername(username);
        UserService service = new UserService();
        if(service.UsernameExist(user)){
            //如果存在
            response.getWriter().write("用户名已存在");
        }else {
            response.getWriter().write("用户名可使用");
        }
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
